//
//  Equation.m
//  MathMasterMain
//
//  Created by Jordon Phillips on 3/23/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "Equation.h"
#import <stdlib.h>


@implementation Equation
@synthesize firstNumber, secondNumber, operand, solution, difficulty;

//generates a new equation at random
- (void)generateEquation{
	int numMax=5;
	int opMax=3;
	if(difficulty==2)//hard
		numMax=9;
	if(difficulty==0)//easy
		opMax=2;
	firstNumber=arc4random() % numMax;//randomly chooses a number between 0 and 8
	firstNumber++;//changes the above to be between 1 and 9
	if(difficulty==0)//easy
		secondNumber=arc4random()%(firstNumber+1);
	else
		secondNumber=arc4random()% (numMax+1);//randomly chooses a number between 0 and 9
	operand=arc4random() % opMax;// randomly chooses a number between 0 and 2
	if(operand==0)//operand=0 means addition
		solution=firstNumber+secondNumber;
	else if(operand==1){//operand=1 means subraction
		solution=firstNumber-secondNumber;
	}else if(operand==2)//operand=2 means multiplication
		solution=firstNumber*secondNumber;
}
//checks if a number fills in the equation correctly
- (bool)checkAnswer:(int)ans{
	if(ans==secondNumber)
		return TRUE;
	return FALSE;
}
@end
